﻿using System;
using System.Data;
using System.Collections;
using CE.Database;

/// <summary>
/// Summary description for DriverClaimHistoryDB
/// </summary>
/// 
namespace CE.CarInsurance
{
    public class DriverClaimHistoryDB
    {
        public DriverClaimHistoryDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(DriverClaimHistory driverhis)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocDriverClaimHistoryInsertUpdateSingleItem";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@ClaimId", driverhis.ClaimId);
            _sPara.Add("@CECarId", driverhis.CECarId);
            _sPara.Add("@ProviderCompanyId", driverhis.ProviderCompanyId);
            _sPara.Add("@AccidentDate", driverhis.AccidentDate);
            _sPara.Add("@NatureofAccident", driverhis.NatureofAccident);
            _sPara.Add("@ClaimAmount", driverhis.ClaimAmount);
            _sPara.Add("@TypeofClaim", driverhis.TypeofClaim);
            _sPara.Add("@RefCEUserId", driverhis.RefCEUserId);
            _sPara.Add("@Status", driverhis.Status);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public DriverClaimHistory GetDriverClaimHistory(Int64 CarId, Int64 ProviderCompanyId)
        {
            DriverClaimHistory _driverhis = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocDriverClaimHistoryByCarIdSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@CECarId", CarId);
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _driverhis = new DriverClaimHistory();
                    _driverhis = FillDataRecord(_dt);
                }
            }
            return _driverhis;
        }

        private DriverClaimHistory FillDataRecord(DataTable myDataTable)
        {
            DriverClaimHistory myClaimHistory = new DriverClaimHistory();
            myClaimHistory.ClaimId = Convert.ToInt64(myDataTable.Rows[0]["ClaimId"].ToString());
            myClaimHistory.CECarId = Convert.ToInt64(myDataTable.Rows[0]["CECarId"].ToString());
            myClaimHistory.ProviderCompanyId = Convert.ToByte(myDataTable.Rows[0]["ProviderCompanyId"].ToString());
            myClaimHistory.AccidentDate = Convert.ToDateTime(myDataTable.Rows[0]["AccidentDate"].ToString());
            myClaimHistory.NatureofAccident = myDataTable.Rows[0]["NatureofAccident"].ToString();
            myClaimHistory.ClaimAmount = Convert.ToSingle(myDataTable.Rows[0]["ClaimAmount"].ToString());
            myClaimHistory.TypeofClaim = myDataTable.Rows[0]["TypeofClaim"].ToString();
            myClaimHistory.RefCEUserId = Convert.ToInt64(myDataTable.Rows[0]["RefCEUserId"].ToString());
            myClaimHistory.Status = Convert.ToBoolean(myDataTable.Rows[0]["Status"].ToString());
            return myClaimHistory;
        }

    }
}